﻿using System;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;
using System.Collections;
using He.Common;

namespace He.API.WeiXin
{
    public class MutiMsgHandle
    {
        /// <summary>
        /// 根据group_id群发消息
        /// </summary>
        /// <param name="group_id"></param>
        /// <param name="media_id"></param>
        /// <param name="msgtype"></param>
        /// <returns></returns>
        public static int Send(string group_id, string media_id, string msgtype)
        {
            string posturl = "https://api.weixin.qq.com/cgi-bin/message/mass/sendall?access_token="+CheckSignature.GetAccessToken();
            MessageSend send = new MessageSend();
            send.filter = new Hashtable();
            send.mpnews = new Hashtable();
            Hashtable hash = new Hashtable();
            send.filter["group_id"] = group_id;
            send.mpnews["media_id"] = media_id;
            send.msgtype = msgtype;
            JsonSerializerSettings settings = new JsonSerializerSettings { NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore };
            string json = JsonConvert.SerializeObject(send, settings);
            string result = HttpHelper.HttpPost(posturl, json);
            send = JsonConvert.DeserializeObject<MessageSend>(result);
            return send.errcode;
        }
    }
}
